﻿using Ast.Framework.FileSystems.Paths;

namespace Ast.Framework.FileSystems.SiteFolders
{
    public interface IModuleFolderRoot
    {
        string Path { get; }
    }

    public class ModuleFolderRoot : IModuleFolderRoot
    {
        private readonly ISiteFolderRoot _siteFolderRoot;
        private readonly IPathProvider _pathProvider;

        public ModuleFolderRoot(ISiteFolderRoot siteFolderRoot, IPathProvider pathProvider)
        {
            _siteFolderRoot = siteFolderRoot;
            _pathProvider = pathProvider;
        }

        public string Path
        {
            get
            {
                var path = _pathProvider.Combine(_siteFolderRoot.Path, "Modules");
                if (_pathProvider.DirectoryExists(path)) return path;
                path = _pathProvider.Combine(_siteFolderRoot.Path, "..\\..\\Modules");
                if (_pathProvider.DirectoryExists(path)) return path;

                return null;
            }
        }
    }
}